package com.baizhi.service.impl;

import com.baizhi.entity.Article;
import com.baizhi.service.ArticleService;
import com.baizhi.dao.ArticleDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ArticleServiceImpl implements ArticleService {
    @Autowired
    private ArticleDao articleDao;
    @Override
    public Map insertArticle(Article article) {
        Map map=new HashMap();
        int count=articleDao.insertArticle(article);
        if(count>0){
            map.put("isInsert",true);
        }else{
            map.put("isInsert",false);
        }
        return map;
    }

    @Override
    public Map deleteArticleById(int articleId) {
        Map map=new HashMap();
        int count=articleDao.deleteArticleById(articleId);
        if(count>0){
            map.put("isInsert",true);
        }else{
            map.put("isInsert",false);
        }
        return map;
    }

    @Override
    public Map updateArticle(Article article) {
        Map map=new HashMap();
        int count=articleDao.updateArticle(article);
        if(count>0){
            map.put("isInsert",true);
        }else{
            map.put("isInsert",false);
        }
        return map;
    }

    @Override
    public Map showArticle(int page, int limit) {
        Map map=new HashMap();
        int offset=(page-1)*limit;
        List<Article> list=articleDao.selectAllArticle(offset,limit);
        int count=articleDao.selectCount();
        map.put("data",list);
        map.put("count",count);
        map.put("code",0);
        map.put("msg","");
        return map;
    }

    @Override
    public Article selectOne(int articleId) {
        Article article=articleDao.selectOne(articleId);
        return article;
    }

}
